﻿Public Class add_mix

  
    Private Sub btn_close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_close.Click
        Me.Close()
    End Sub

    Private Sub btn_ok_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok_add.Click
        ''Dim ctrl As Control
        ''For Each ctrl In Me.Controls
        ''    If (TypeOf ctrl Is TextBox) And ctrl.Text = "" Then
        ''        MessageBox.Show("Please fill all fields!", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error)
        ''        Exit Sub
        ''    End If
        ''Next
        If txt_mix_code.Text = "" Or txt_mix_name.Text = "" Or txt_sh_add.Text = "" Or txt_sh_con.Text = "" Or txt_sh_corn1.Text = "" Or txt_sh_corn2.Text = "" Or txt_sh_ex1.Text = "" Or txt_sh_ex2.Text = "" Or txt_sh_gelotine.Text = "" Or txt_sh_oil.Text = "" Or txt_sh_rada.Text = "" Or txt_sh_sn.Text = "" Or txt_sh_soy1.Text = "" Or txt_sh_soy2.Text = "" Or txt_sl_add.Text = "" Or txt_sl_con.Text = "" Or txt_sl_corn1.Text = "" Or txt_sl_corn2.Text = "" Or txt_sl_ex1.Text = "" Or txt_sl_ex2.Text = "" Or txt_sl_gelotine.Text = "" Or txt_sl_oil.Text = "" Or txt_sl_rada.Text = "" Or txt_sl_sn.Text = "" Or txt_sl_soy1.Text = "" Or txt_sl_soy2.Text = "" Or txt_t_add.Text = "" Or txt_t_con.Text = "" Or txt_t_corn1.Text = "" Or txt_t_corn2.Text = "" Or txt_t_ex1.Text = "" Or txt_t_ex2.Text = "" Or txt_t_gelotine.Text = "" Or txt_t_oil.Text = "" Or txt_t_rada.Text = "" Or txt_t_sn.Text = "" Or txt_t_soy1.Text = "" Or txt_t_soy2.Text = "" Or txt_wf_add.Text = "" Or txt_wf_con.Text = "" Or txt_wf_corn1.Text = "" Or txt_wf_corn2.Text = "" Or txt_wf_ex1.Text = "" Or txt_wf_ex2.Text = "" Or txt_wf_gelotine.Text = "" Or txt_wf_oil.Text = "" Or txt_wf_rada.Text = "" Or txt_wf_sn.Text = "" Or txt_wf_soy1.Text = "" Or txt_wf_soy2.Text = "" Or txt_wh_add.Text = "" Or txt_wh_con.Text = "" Or txt_wh_corn1.Text = "" Or txt_wh_corn2.Text = "" Or txt_wh_ex1.Text = "" Or txt_wh_ex2.Text = "" Or txt_wh_gelotine.Text = "" Or txt_wh_oil.Text = "" Or txt_wh_rada.Text = "" Or txt_wh_sn.Text = "" Or txt_wh_soy1.Text = "" Or txt_wh_soy2.Text = "" Or txt_wl_add.Text = "" Or txt_wl_con.Text = "" Or txt_wl_corn1.Text = "" Or txt_wl_corn2.Text = "" Or txt_wl_ex1.Text = "" Or txt_wl_ex2.Text = "" Or txt_wl_gelotione.Text = "" Or txt_wl_oil.Text = "" Or txt_wl_rada.Text = "" Or txt_wl_sn.Text = "" Or txt_wl_soy1.Text = "" Or txt_wl_soy2.Text = "" Then

            MessageBox.Show("Please fill all fields!", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else


            If GetTable("SELECT * FROM Batchs WHERE BatchName='" & txt_mix_name.Text & "'").Rows.Count <> 0 Then
                MessageBox.Show("هذا الاسم موجود من قبل ", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            ElseIf GetTable("SELECT * FROM Batchs WHERE BatchCode='" & txt_mix_code.Text & "'").Rows.Count <> 0 Then
                MessageBox.Show("هذا الكود موجود من قبل ", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If

            If MessageBox.Show("هل انت متأكد من حفظ البيانات", "تنبيه", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) = Windows.Forms.DialogResult.Yes Then
                Dim x As Integer
                InsertBatch(txt_mix_name.Text, txt_mix_code.Text)
                x = GetTable("SELECT * FROM Batchs").Rows.Count
                InsertBatchDetail(x, "1", txt_t_corn1.Text, Val(txt_sl_corn1.Text * 5), Val(txt_sh_corn1.Text * 5), Val((txt_wl_corn1.Text) - (txt_wf_corn1.Text)), txt_wh_corn1.Text, txt_wf_corn1.Text)
                InsertBatchDetail(x, "2", txt_t_corn2.Text, Val(txt_sl_corn2.Text * 5), Val(txt_sh_corn2.Text * 5), Val((txt_wl_corn2.Text) - (txt_wf_corn2.Text)), txt_wh_corn2.Text, txt_wf_corn2.Text)
                InsertBatchDetail(x, "3", txt_t_soy1.Text, Val(txt_sl_soy1.Text * 5), Val(txt_sh_soy1.Text * 5), Val((txt_wl_soy1.Text) - (txt_wf_soy1.Text)), txt_wh_soy1.Text, txt_wf_soy1.Text)
                InsertBatchDetail(x, "4", txt_t_soy2.Text, Val(txt_sl_soy2.Text * 5), Val(txt_sh_soy2.Text * 5), Val((txt_wl_soy2.Text) - (txt_wf_soy2.Text)), txt_wh_soy2.Text, txt_wf_soy2.Text)
                InsertBatchDetail(x, "5", txt_t_sn.Text, Val(txt_sl_sn.Text * 5), Val(txt_sh_sn.Text * 5), Val((txt_wl_sn.Text) - (txt_wf_sn.Text)), txt_wh_sn.Text, txt_wf_sn.Text)
                InsertBatchDetail(x, "6", txt_t_rada.Text, Val(txt_sl_rada.Text * 5), Val(txt_sh_rada.Text * 5), Val((txt_wl_rada.Text) - (txt_wf_rada.Text)), txt_wh_rada.Text, txt_wf_rada.Text)
                InsertBatchDetail(x, "7", txt_t_con.Text, Val(txt_sl_con.Text * 5), Val(txt_sh_con.Text * 5), Val((txt_wl_con.Text) - (txt_wf_con.Text)), txt_wh_con.Text, txt_wf_con.Text)
                InsertBatchDetail(x, "8", txt_t_gelotine.Text, Val(txt_sl_gelotine.Text * 5), Val(txt_sh_gelotine.Text * 5), Val((txt_wl_gelotione.Text) - (txt_wf_gelotine.Text)), txt_wh_gelotine.Text, txt_wf_gelotine.Text)
                InsertBatchDetail(x, "9", txt_t_oil.Text, Val(txt_sl_oil.Text * 5), Val(txt_sh_oil.Text * 5), Val((txt_wl_oil.Text) - (txt_wf_oil.Text)), txt_wh_oil.Text, txt_wf_oil.Text)
                InsertBatchDetail(x, "10", txt_t_add.Text, Val(txt_sl_add.Text * 5), Val(txt_sh_add.Text * 5), Val((txt_wl_add.Text) - (txt_wf_add.Text)), txt_wh_add.Text, txt_wf_add.Text)
                InsertBatchDetail(x, "11", txt_t_ex1.Text, Val(txt_sl_ex1.Text * 5), Val(txt_sh_ex1.Text * 5), Val((txt_wl_ex1.Text) - (txt_wf_ex1.Text)), txt_wh_ex1.Text, txt_wf_ex1.Text)
                InsertBatchDetail(x, "12", txt_t_ex2.Text, Val(txt_sl_ex2.Text * 5), Val(txt_sh_ex2.Text * 5), Val((txt_wl_ex2.Text) - (txt_wf_ex2.Text)), txt_wh_ex2.Text, txt_wf_ex2.Text)
            End If
        End If
    End Sub
End Class